<!DOCTYPE html>












  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">









  
  
    
  
  <link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/Han/3.3.0/han.min.css">




<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



















  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=6.3.0" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.3.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.3.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '6.3.0',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="java代码由于可以反编译，因此对于一些敏感逻辑，最好使用jni开发。 将开发好的so文件打包进jar文件，运行时从jar加载 基于Clion开发jnilib1. 定义接口文件1234567891011package base.jni;/** * @author &amp;lt;a href=mailto:ktyi@iflytek.com&amp;gt;伊开堂&amp;lt;/a&amp;gt; * @date 2021/6/1">
<meta name="keywords" content="java,jni">
<meta property="og:type" content="article">
<meta property="og:title" content="JNI开发">
<meta property="og:url" content="http://codertang.com/2021/06/11/jni/index.html">
<meta property="og:site_name" content="Tonny&#39;s Blog">
<meta property="og:description" content="java代码由于可以反编译，因此对于一些敏感逻辑，最好使用jni开发。 将开发好的so文件打包进jar文件，运行时从jar加载 基于Clion开发jnilib1. 定义接口文件1234567891011package base.jni;/** * @author &amp;lt;a href=mailto:ktyi@iflytek.com&amp;gt;伊开堂&amp;lt;/a&amp;gt; * @date 2021/6/1">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2021-06-15T02:52:14.831Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JNI开发">
<meta name="twitter:description" content="java代码由于可以反编译，因此对于一些敏感逻辑，最好使用jni开发。 将开发好的so文件打包进jar文件，运行时从jar加载 基于Clion开发jnilib1. 定义接口文件1234567891011package base.jni;/** * @author &amp;lt;a href=mailto:ktyi@iflytek.com&amp;gt;伊开堂&amp;lt;/a&amp;gt; * @date 2021/6/1">






  <link rel="canonical" href="http://codertang.com/2021/06/11/jni/">



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>JNI开发 | Tonny's Blog</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Tonny's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">莫等闲, 白了少年头, 空悲切</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>
  </li>

      
      
    </ul>
  

  
    

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://codertang.com/2021/06/11/jni/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tonny Yi">
      <meta itemprop="description" content="Coding, Life, Zen">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tonny's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">JNI开发
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2021-06-11 16:27:06" itemprop="dateCreated datePublished" datetime="2021-06-11T16:27:06+08:00">2021-06-11</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2021-06-15 10:52:14" itemprop="dateModified" datetime="2021-06-15T10:52:14+08:00">2021-06-15</time>
              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/java/" itemprop="url" rel="index"><span itemprop="name">java</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <p>java代码由于可以反编译，因此对于一些敏感逻辑，最好使用jni开发。</p>
<p>将开发好的so文件打包进jar文件，<a href="https://xiaoyue26.github.io/2019/09/08/2019-09/JNI%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E5%BC%95%E7%94%A8so%E6%96%87%E4%BB%B6/" target="_blank" rel="noopener">运行时从jar加载</a></p>
<h1 id="基于Clion开发jnilib"><a href="#基于Clion开发jnilib" class="headerlink" title="基于Clion开发jnilib"></a>基于Clion开发jnilib</h1><h3 id="1-定义接口文件"><a href="#1-定义接口文件" class="headerlink" title="1. 定义接口文件"></a>1. 定义接口文件</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> base.jni;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> &lt;a href=mailto:ktyi@iflytek.com&gt;伊开堂&lt;/a&gt;</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2021/6/11</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyService</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">native</span> String <span class="title">hello</span><span class="params">(<span class="keyword">int</span> times, String name)</span></span>;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="2-生成头文件"><a href="#2-生成头文件" class="headerlink" title="2. 生成头文件"></a>2. 生成头文件</h3><p>在编译出来的class文件的根目录（如：<code>target/classes</code>目录）执行如下目录，之后会在当前目录生成头文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">javah base.jni.MyService</span><br></pre></td></tr></table></figure>
<p>头文件<code>base_jni_MyService.h</code>内容如下</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* DO NOT EDIT THIS FILE - it is machine generated */</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;jni.h&gt;</span></span></span><br><span class="line"><span class="comment">/* Header for class base_jni_MyService */</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> _Included_base_jni_MyService</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> _Included_base_jni_MyService</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> __cplusplus</span></span><br><span class="line"><span class="keyword">extern</span> <span class="string">"C"</span> &#123;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * Class:     base_jni_MyService</span></span><br><span class="line"><span class="comment"> * Method:    hello</span></span><br><span class="line"><span class="comment"> * Signature: (ILjava/lang/String;)Ljava/lang/String;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">JNIEXPORT jstring JNICALL Java_base_jni_MyService_hello</span><br><span class="line">  (JNIEnv *, jobject, jint, jstring);</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> __cplusplus</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br></pre></td></tr></table></figure>
<h3 id="2-使用Clion创建新项目"><a href="#2-使用Clion创建新项目" class="headerlink" title="2. 使用Clion创建新项目"></a>2. 使用Clion创建新项目</h3><p>项目类型选择<code>C Excutable</code>，保持<code>C99</code></p>
<h3 id="3-复制JDK安装目录下的jni-h和jni-md-h到Clion项目目录"><a href="#3-复制JDK安装目录下的jni-h和jni-md-h到Clion项目目录" class="headerlink" title="3. 复制JDK安装目录下的jni.h和jni_md.h到Clion项目目录"></a>3. 复制JDK安装目录下的<code>jni.h</code>和<code>jni_md.h</code>到Clion项目目录</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/</span><br><span class="line">cp include/jni.h include/darwin/jni_md.h ~/workspakce/clion_jni</span><br></pre></td></tr></table></figure>
<h3 id="4-复制idea中的头文件base-jni-MyService-h到Clion，修改其内容中的-include-lt-jni-h-gt-为-include-“jni-h”"><a href="#4-复制idea中的头文件base-jni-MyService-h到Clion，修改其内容中的-include-lt-jni-h-gt-为-include-“jni-h”" class="headerlink" title="4. 复制idea中的头文件base_jni_MyService.h到Clion，修改其内容中的#include &lt;jni.h&gt;为#include “jni.h”"></a>4. 复制idea中的头文件<code>base_jni_MyService.h</code>到Clion，修改其内容中的<strong>#include &lt;jni.h&gt;</strong>为<strong>#include “jni.h”</strong></h3><h3 id="5-新建base-jni-MyService-c并编译"><a href="#5-新建base-jni-MyService-c并编译" class="headerlink" title="5. 新建base_jni_MyService.c并编译"></a>5. 新建<code>base_jni_MyService.c</code>并编译</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">// Created by Tonny Yi on 2021/6/11.</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"base_jni_MyService.h"</span></span></span><br><span class="line"></span><br><span class="line">JNIEXPORT jstring JNICALL Java_base_jni_MyService_hello</span><br><span class="line">        (JNIEnv *env, jobject, jint, jstring) &#123;</span><br><span class="line">    <span class="keyword">return</span> (*env)-&gt;NewStringUTF(env, <span class="string">"Hello..."</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="6-编译库，库名称必须是lib-jnilib格式"><a href="#6-编译库，库名称必须是lib-jnilib格式" class="headerlink" title="6. 编译库，库名称必须是lib*.jnilib格式"></a>6. 编译库，库名称必须是<strong>lib*.jnilib</strong>格式</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc base_jni_MyService.c -shared -fPIC -o libtest.jnilib</span><br></pre></td></tr></table></figure>
<h3 id="7-复制编译后的库文件到java动态链接库，通过System-getProperty-quot-java-library-path-quot-可以获取链接库目录-也可以自行设置java-library-path的路径"><a href="#7-复制编译后的库文件到java动态链接库，通过System-getProperty-quot-java-library-path-quot-可以获取链接库目录-也可以自行设置java-library-path的路径" class="headerlink" title="7. 复制编译后的库文件到java动态链接库，通过System.getProperty(&quot;java.library.path&quot;)可以获取链接库目录,也可以自行设置java.library.path的路径"></a>7. 复制编译后的库文件到java动态链接库，通过<code>System.getProperty(&quot;java.library.path&quot;)</code>可以获取链接库目录,也可以<a href="https://blog.csdn.net/quqibing001/article/details/51201768" target="_blank" rel="noopener">自行设置java.library.path的路径</a></h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp libtest.jnilib ~/Library/Java/Extensions</span><br></pre></td></tr></table></figure>
<p>也可以在运行代码时指定<code>java.library.path</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-Djava.library.path=E:\workspace\StudyJNI\lib</span><br></pre></td></tr></table></figure>
<p>最后执行test</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">JniTest</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        System.loadLibrary(<span class="string">"test"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> MyService().hello(<span class="number">32</span>, <span class="string">"sss"</span>));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="基于IDEA开发so"><a href="#基于IDEA开发so" class="headerlink" title="基于IDEA开发so"></a>基于IDEA开发so</h2>
      
    </div>

    

    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Tonny Yi</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://codertang.com/2021/06/11/jni/" title="JNI开发">http://codertang.com/2021/06/11/jni/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc/4.0/" rel="external nofollow" target="_blank">CC BY-NC 4.0</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/jni/" rel="tag"># jni</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/06/11/jar-command/" rel="next" title="jar命令">
                <i class="fa fa-chevron-left"></i> jar命令
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/06/16/vim/" rel="prev" title="vim">
                vim <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.png" alt="Tonny Yi">
            
              <p class="site-author-name" itemprop="name">Tonny Yi</p>
              <p class="site-description motion-element" itemprop="description">Coding, Life, Zen</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">49</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">42</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">59</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/tonnyyi" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:tonnyemails@gmail.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
            </div>
          

          
          
            <div class="cc-license motion-element" itemprop="license">
              <a href="https://creativecommons.org/licenses/by-nc/4.0/" class="cc-opacity" target="_blank">
                <img src="/images/cc-by-nc.svg" alt="Creative Commons">
              </a>
            </div>
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#基于Clion开发jnilib"><span class="nav-number">1.</span> <span class="nav-text">基于Clion开发jnilib</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-定义接口文件"><span class="nav-number">1.0.1.</span> <span class="nav-text">1. 定义接口文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-生成头文件"><span class="nav-number">1.0.2.</span> <span class="nav-text">2. 生成头文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-使用Clion创建新项目"><span class="nav-number">1.0.3.</span> <span class="nav-text">2. 使用Clion创建新项目</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-复制JDK安装目录下的jni-h和jni-md-h到Clion项目目录"><span class="nav-number">1.0.4.</span> <span class="nav-text">3. 复制JDK安装目录下的jni.h和jni_md.h到Clion项目目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-复制idea中的头文件base-jni-MyService-h到Clion，修改其内容中的-include-lt-jni-h-gt-为-include-“jni-h”"><span class="nav-number">1.0.5.</span> <span class="nav-text">4. 复制idea中的头文件base_jni_MyService.h到Clion，修改其内容中的#include &lt;jni.h&gt;为#include “jni.h”</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-新建base-jni-MyService-c并编译"><span class="nav-number">1.0.6.</span> <span class="nav-text">5. 新建base_jni_MyService.c并编译</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-编译库，库名称必须是lib-jnilib格式"><span class="nav-number">1.0.7.</span> <span class="nav-text">6. 编译库，库名称必须是lib*.jnilib格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-复制编译后的库文件到java动态链接库，通过System-getProperty-quot-java-library-path-quot-可以获取链接库目录-也可以自行设置java-library-path的路径"><span class="nav-number">1.0.8.</span> <span class="nav-text">7. 复制编译后的库文件到java动态链接库，通过System.getProperty(&quot;java.library.path&quot;)可以获取链接库目录,也可以自行设置java.library.path的路径</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#基于IDEA开发so"><span class="nav-number">1.1.</span> <span class="nav-text">基于IDEA开发so</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tonny Yi</span>

  

  
</div>


  <script src="https://unpkg.com/mermaid@7.1.2/dist/mermaid.min.js"></script>
  <script>
    if (window.mermaid) {
      mermaid.initialize("");
    }
  </script>





  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Mist</a></div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.3.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.3.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.3.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.3.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.3.0"></script>



  



	





  





  










  





  

  

  

  

  
  

  

  

  

  

  
  <style>
    .copy-btn {
      display: inline-block;
      padding: 6px 12px;
      font-size: 13px;
      font-weight: 700;
      line-height: 20px;
      color: #333;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      background-color: #eee;
      background-image: linear-gradient(#fcfcfc, #eee);
      border: 1px solid #d5d5d5;
      border-radius: 3px;
      user-select: none;
      outline: 0;
    }

    .highlight-wrap .copy-btn {
      transition: opacity .3s ease-in-out;
      opacity: 0;
      padding: 2px 6px;
      position: absolute;
      right: 4px;
      top: 8px;
    }

    .highlight-wrap:hover .copy-btn,
    .highlight-wrap .copy-btn:focus {
      opacity: 1
    }

    .highlight-wrap {
      position: relative;
    }
  </style>
  <script>
    $('.highlight').each(function (i, e) {
      var $wrap = $('<div>').addClass('highlight-wrap')
      $(e).after($wrap)
      $wrap.append($('<button>').addClass('copy-btn').append('复制').on('click', function (e) {
        var code = $(this).parent().find('.code').find('.line').map(function (i, e) {
          return $(e).text()
        }).toArray().join('\n')
        var ta = document.createElement('textarea')
        document.body.appendChild(ta)
        ta.style.position = 'absolute'
        ta.style.top = '0px'
        ta.style.left = '0px'
        ta.value = code
        ta.select()
        ta.focus()
        var result = document.execCommand('copy')
        document.body.removeChild(ta)
        
          if(result)$(this).text('复制成功')
          else $(this).text('复制失败')
        
        $(this).blur()
      })).on('mouseleave', function (e) {
        var $b = $(this).find('.copy-btn')
        setTimeout(function () {
          $b.text('复制')
        }, 300)
      }).append(e)
    })
  </script>


</body>
</html>
